package cn.xiaolang.function.annotation;

import java.lang.reflect.Method;

public class MyRetentionTarget {

	// 自定义的注解如果有默认值，那么属性可以写也可以不写，如果没有默认值，那么该属性就必须重写

	@CustomRetention(world = "xiaolang-world")
	public void doSomething() {
		System.out.println("测试自定义的注解应用！！");
	}

	public static void main(String[] args) throws NoSuchMethodException, SecurityException {
		Method method = MyRetentionTarget.class.getMethod("doSomething");

		// 如果MyRetention的doSomething方法上存在CustomeRetention注解，则为true
		if (method.isAnnotationPresent(CustomRetention.class)) {
			CustomRetention annotation = method.getAnnotation(CustomRetention.class);
			System.out.println("打印自定义注解的内容：");
			System.out.println(annotation.world());
			System.out.println(annotation.style());
			System.out.println(annotation.array());

		}
	}
}
